﻿<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>会员卡</title>
		<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
		<link href="../css/style.css" type="text/css" rel="stylesheet" />
		<script type="text/javascript" src="../js/common.js"></script>
		<script type="text/javascript" src="../js/utils.js"></script>
		<script type="text/javascript" src="../js/checkLogin.js"></script>
		<script type="text/javascript" src="../js/jquery.pager.js"></script>
		<script type="text/javascript" src="../js/pagination.js"></script>
		<script type="text/javascript" src="../js/shopSelecter.js"></script>
		<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
		<script type="text/javascript" src="../js/find.js"></script>
		<script type="text/javascript" src="../js/qmsk-1.2.js"></script>
		<script type="text/javascript" src="../js/dataTable.js"></script>
		<script type="text/javascript">
			var _shopId = '';
			var _memberId = '';
			var _pagination = null;
			$(function() {
				qmsk.initSelect({
					url : '../memberState/find/all/0/100',
					id : 'searchState',
					heads : ['id', 'name'],
					defaults : {
						key : '所有',
						value : ' '
					}
				});

				loadMemberLeverSelect();

				$('.doubledate').kuiDate({
					className : 'doubledate',
					isDisabled : "0"
				});

				initShopSelecter();
			});

			function loadMemberLeverSelect() {
				var shopId = $("#shopName").val();
				if (qmsk.isEmpty(shopId)) {
					return;
				}
				qmsk.initSelect({
					url : '../memberLevel/find/memberLevelList/0/10?shopId=' + shopId,
					id : 'searchLeave',
					heads : ['ID', 'Name'],
					defaults : {
						key : '请选择会员级别',
						value : ' '
					}
				});
			}

			/**
			 * 初始化店面选择器
			 */
			function initShopSelecter() {
				refreshInput($(".serWrapper"));
				$("#shopIsChoosed").removeAttr("checked");
				$("#shopName").attr("disabled", "disabled");

				$("#shopIsChoosed").bind("click", function() {
					var checked = $(this).attr("checked");
					if (checked) {
						$("#shopName").removeAttr("disabled");
					} else {
						$("#shopName").attr("disabled", "disabled");
						$("#shopName").empty();
						$("#searchLeave").empty();
					}
				});
			}

			/**
			 * 店面选择后的回调函数，这里需要去加载会员级别下拉框
			 */
			function shopSelected(shopId, shopName) {
				qmsk.initSelect({
					url : '../memberLevel/find/memberLevelList/0/10?shopId=' + shopId,
					id : 'searchLeave',
					heads : ['ID', 'Name'],
					defaults : {
						key : '请选择会员级别',
						value : ' '
					}
				});
			}

			/**
			 * 分页查询
			 */
			function search() {

				var shopId = $("#shopName").val();
				if (shopId == null) {
					shopId = '';
				}
				var status = $("#searchState").val();
				if (IsEmpty(status)) {
					status = '';
				}
				var memberCardNo = $("#searchCardNumber").val();
				var customerName = $("#searchName").val();
				var mp = $("#searchMp").val();
				var levelId = $("#searchLeave").val();
				if (IsEmpty(levelId)) {
					levelId = '';
				}
				var license = $("#searchLicense").val();

				_pagination = new Pagination({
					url : '../memberQuery/find/list',
					data : {
						shopId : shopId,
						status : status,
						memberCardNo : memberCardNo,
						customerName : customerName,
						mp : mp,
						levelId : levelId,
						license : license
					},
					success : printDataToPage,
					pagerHandler : 'pager'
				});
			}

			function printDataToPage(rst) {
				//"customerID","createFileTime","memberCardNo","customerName",
				//"mp", "integralAmount", "depositAmount", "cashCouponAmount", "couponAmount", "status", "memberStateName", "shopID", "levelID", "license"
				dataTable({
					tbodyId : 'memberList',
					heads : ["createFileTime", "memberCardNo", "customerName", "mp", "integralAmount", "depositAmount", "cashCouponAmount", "couponAmount", "memberStateName", ["shopID", "memberID", "customerID"]],
					rst : rst,
					sup : {
						id : 'sup',
						template : '共 [index] 条'
					},
					handler : [{
						col : 9,
						f : detailButton
					}]
				});
			}

			function detailButton(heads, row) {
				return "<input type='button' value='详情' onclick='toDetail(" + heads[0] + "," + heads[1] + "," + heads[2] + ");'  class='common_btn'>";
			}

			function toDetail(shopId, memberID, customerID) {
				qmsk.get('../memberQuery/find/detail/' + memberID + '/' + shopId, printDetailToPage);
				//loadCarList(customerID);
				openDetailPanel();
			}

			/**
			 * 将详细信息显示到页面上
			 */
			function printDetailToPage(response) {
				var rst = response.rst;
				$("#addShopId").val(getHtmlString(getHeadIndexValue(0, rst, "shopName")));
				$("#addCustomerName").val(getHtmlString(getHeadIndexValue(0, rst, "customerName")));
				$("#addSex").val(getHtmlString(getHeadIndexValue(0, rst, "sex")));
				$("#addMp").val(getHtmlString(getHeadIndexValue(0, rst, "mp")));
				$("#addTel").val(getHtmlString(getHeadIndexValue(0, rst, "tel")));

				$("#addBirthday").val(getHtmlString(getHeadIndexValue(0, rst, "birthday")));
				$("#addEmail").val(getHtmlString(getHeadIndexValue(0, rst, "email")));
				$("#addZipCode").val(getHtmlString(getHeadIndexValue(0, rst, "zipCode")));

				$("#addIDNumber").val(getHtmlString(getHeadIndexValue(0, rst, "IDNumber")));
				$("#addIndustryType").val(getHtmlString(getHeadIndexValue(0, rst, "industryType")));
				$("#addCompanyName").val(getHtmlString(getHeadIndexValue(0, rst, "companyName")));

				$("#addCompanyDuty").val(getHtmlString(getHeadIndexValue(0, rst, "companyDuty")));
				$("#addAddress").val(getHtmlString(getHeadIndexValue(0, rst, "address")));
				$("#addCustomerFrom").val(getHtmlString(getHeadIndexValue(0, rst, "custFrom")));

				$("#memberFee").val(getHtmlString(getHeadIndexValue(0, rst, "memberFee")));
				$("#addMemberStatus").val(getHtmlString(getHeadIndexValue(0, rst, "memberStateName")));

				$("#createFileTime").val(getHtmlString(getHeadIndexValue(0, rst, "createFileTime")));
				$("#validDay").val(getHtmlString(getHeadIndexValue(0, rst, "validityDay")));
				$("#validDateTime").val(getHtmlString(getHeadIndexValue(0, rst, "validDateTime")));

				$("#addMemberCardNO").val(getHtmlString(getHeadIndexValue(0, rst, "memberCardNo")));

				$("#addNote").val(getHtmlString(getHeadIndexValue(0, rst, "memberMemo")));
				$("#depositAmount").val(getHtmlString(getHeadIndexValue(0, rst, "depositAmount")));
				$("#couponAmount").val(getHtmlString(getHeadIndexValue(0, rst, "cashCouponAmount")));

				$("#consumeAmount").val(getHtmlString(getHeadIndexValue(0, rst, "consumeAmount")));
				$("#integralAmount").val(getHtmlString(getHeadIndexValue(0, rst, "integralAmount")));
				$("#discount").val(getHtmlString(getHeadIndexValue(0, rst, "discount")));

				// 会员卡 可操作按钮
				var levelFlag = 0;
				_shopId = getHtmlString(getHeadIndexValue(0, rst, "shopID"));
				_memberId = getHtmlString(getHeadIndexValue(0, rst, "memberID"));
				var memberstatus = getHtmlString(getHeadIndexValue(0, rst, "memberStateId"));
				if (memberstatus == 2) {
					$("#reportLossButton,#upgradeButton,#cardBackButton").show();
					$("#recoverButton").hide();
				} else if (memberstatus == 4 || memberstatus == 7) {
					$("#reportLossButton,#upgradeButton,#cardBackButton").hide();
					$("#recoverButton").show();
				} else if (memberstatus == 6) {

					//load member level

					qmsk.initSelect({
						url : '../memberLevel/find/memberLevelList/0/10?shopId=' + _shopId,
						id : 'addLevelId',
						heads : ['ID', 'Name'],
						defaults : {
							key : '请选择会员级别',
							value : ' '
						}
					});

					$("#addLevelId").val(getHtmlString(getHeadIndexValue(0, rst, "levelId")));

					levelFlag = 1;

					$("#reportLossButton,#upgradeButton,#cardBackButton").hide();
					$("#recoverButton").show();
				} else {
					$("#reportLossButton,#upgradeButton,#cardBackButton").hide();
					$("#recoverButton").hide();
				}

				if (levelFlag === 0) {
					var levelId = getHtmlString(getHeadIndexValue(0, rst, "levelId"));
					var levelName = getHtmlString(getHeadIndexValue(0, rst, "levelName"));
					$("#addLevelId").empty();
					$("#addLevelId").append("<option checked='checked' value='" + levelId + "'>" + levelName + "</option>");
				}
			}

			//------------------------会员详情----------------------------------------
			/**
			 * 显示详情面板
			 */
			function openDetailPanel() {
				$("#DetailPanel").show();
				$("#listPanel").hide();
			}

			/**
			 * 关闭详情面板
			 */
			function closeDetailPanel() {
				_pagination.reload();
				$("#DetailPanel").hide();
				$("#listPanel").show();
			}

			/**
			 * 改变会员状态
			 */
			function changeState(toStatus) {

				var text = '';
				if (toStatus == 4) {
					text = '确定要挂失吗?';
				} else if (toStatus == 6) {
					text = '确定要升级吗?';
				} else if (toStatus == 7) {
					text = '确定要退卡吗？';
				} else if (toStatus == 2) {
					text = '确定要恢复正常码？';
				}

				var levelId = $("#addLevelId").val();
				artConfirm(text, function() {
					qmsk.post('../shopmember/memberCardManager/' + _shopId + '/' + _memberId, {
						toStatus : toStatus,
						levelId : levelId
					}, function(message) {
						qmsk.get('../memberQuery/find/detail/' + _memberId + '/' + _shopId, printDetailToPage);
						artAlert('更新成功');
					});
				});
			}
		</script>
	</head>
	<body>
		<div id="yinying"></div>
		<div id="yinying1"></div>

		<!-- 选择 商铺名称的列表 -->
		<div id="shopListPanel_yinying" class="yinying" style="z-index:100;"></div>
		<div id="shopListPanel" class="hideDiv">
			<div style="float: right; margin-bottom: 5px; width: 20px; height: 20px; line-height: 20px; text-align: center; background-color: #eee; margin-bottom: 5px; border: 1px solid #ccc;">
				<span id="shopListPanel_close" style="cursor: pointer; font-size: 14px;">X</span>
			</div>
			<div class="bottom_search">
				<div class="serWrapper" >
					<input type="text" id="shopListPanel_searchName" class="txt" >
					<strong class="refresh" onclick="$(this).prev().val('')">清空</strong>
				</div>
				<input type="button" id="shopListPanel_search"
				style="width: auto; margin-left: 5px;" value="查询"
				class="common_btn">
			</div>
			<table cellpadding="4" cellspacing="0" border="1" width="100%">
				<thead>
					<tr>
						<th>店面ID</th>
						<th>店面名称</th>
						<th>电话</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="shopListPanel_data" ></tbody>
			</table>
			<div id="shopPager" class="pager"></div>
		</div>

		<div class="container" id="container">
			<!-- 会员详情 -->
			<div class="container_R fr" id="DetailPanel" style="display: none;">
				<div class="place">
					会员详情
					<a class="goHome"  href="javaScript:void(0);" onclick='closeDetailPanel()'>返回</a>
				</div>
				<div class="member_search">
					<p>
						<label><span>店面名称:</span>
							<input id="addShopId" readonly="readonly" />
						</label>
						<label><span>姓名:</span>
							<input type="text" id="addCustomerName"  readonly="readonly"  />
						</label>

						<label><span>性别:</span>
							<select  id="addSex" readonly="readonly">
								<option value="0">男</option>
								<option value="1">女</option>
							</select> </label>
					</p>
					<p>
						<label><span>手机:</span>
							<input type="text" id="addMp"  readonly="readonly"  />
						</label>
						<label><span>电话:</span>
							<input type="text" id="addTel" readonly="readonly"  />
						</label>
						<label><span>生日:</span>
							<input type="text"  id="addBirthday"  readonly="readonly" />
						</label>
					</p>
					<p>
						<label><span>Email:</span>
							<input type="text" id="addEmail"  readonly="readonly" />
						</label>
						<label><span>邮编:</span>
							<input type="text" id="addZipCode" readonly="readonly"  />
						</label>
						<label><span>身份证号码:</span>
							<input type="text" id="addIDNumber" readonly="readonly"  />
						</label>
					</p>
					<p>
						<label><span>行业:</span>
							<input type="text"  id="addIndustryType" readonly="readonly" />
						</label>
						<label><span>公司:</span>
							<input type="text" id="addCompanyName" readonly="readonly"  />
						</label>
						<label><span>职位:</span>
							<input type="text" id="addCompanyDuty" readonly="readonly"  />
						</label>
					</p>
					<p>
						<label><span>地址:</span>
							<input type="text" id="addAddress"  readonly="readonly" />
						</label>
						<label><span>客户来源:</span>
							<input type="text" id="addCustomerFrom" readonly="readonly"/>
						</label>
					</p>
					<p>
						<label><span>会员级别:</span> <!-- <input readonly="readonly" id="addLevelId"/> --> <select id="addLevelId"></select> </label>
						<label><span>会员费:</span>
							<input type="text" readonly="readonly" id="memberFee"   />
						</label>
						<label><span>状态:</span>
							<input id="addMemberStatus" readonly="readonly"/>
						</label>
					</p>
					<p>
						<label><span>卡生效日期:</span>
							<input readonly="readonly" type="text" id="createFileTime"   />
						</label>
						<label><span>卡有效期:</span>
							<input readonly="readonly" type="text" id="validDay"   />
						</label>
						<label><span>卡失效期:</span>
							<input readonly="readonly" type="text" id="validDateTime"   />
						</label>
					</p>
					<p>
						<label><span>会员卡号:</span>
							<input type="text" id="addMemberCardNO"  readonly="readonly" />
						</label>
						<!-- <label><span>支付密码:</span>
						<input type="text"  id="addPayPwd"  />
						</label>
						<label><span>APP密码:</span>
						<input type="text" id="addPassword"   />
						</label> -->
					</p>
					<p>
						<label><span>会员备注:</span> 							<textarea id="addNote" readonly="readonly" style="width: 388px; height: 60px;"></textarea> </label>
					</p>
					<p>
						<label><span>储值（元）:</span>
							<input type="text" readonly="readonly" value="0" id="depositAmount"   />
						</label>
						<label><span>代金券（元）:</span>
							<input type="text" readonly="readonly" value="0" id="couponAmount"  />
						</label>
						<label><span>累计消费（元）:</span>
							<input type="text"  readonly="readonly" value="0" id="consumeAmount"   />
						</label>
					</p>
					<p>
						<label><span>积分:</span>
							<input type="text" readonly="readonly" value="0" id="integralAmount"   />
						</label>
						<label><span>折扣:</span>
							<input type="text" readonly="readonly" id="discount"   />
						</label>
					</p>

				</div>
				<div class="submit_btn">
					<input type="button" value="挂失" id="reportLossButton" onclick="changeState(4)" class="common_btn">
					<input type="button" value="升级" id="upgradeButton" onclick="changeState(6)" class="common_btn">
					<input type="button" value="退卡" id="cardBackButton" onclick="changeState(7)" class="common_btn">
					<input type="button" value="恢复正常" id="recoverButton" onclick="changeState(2)" class="common_btn">
					<input type="button" value="返回" onclick="closeDetailPanel()" class="common_btn check_btn">
				</div>
			</div>

			<!-- 会员列表 -->
			<div class="container_R fr" id="listPanel" style="padding: 17px; width: 773px;">
				<div class="place">
					会员卡
				</div>
				<div class="member_search">
					<P>
						<span>
							<input type="checkbox" id="shopIsChoosed" style="width: auto; height: auto;border:none;">
							店面： </span>
						<select id="shopName" class="shopName" onclick="openShopListPanel(this)" style="height: 20px;"></select>
						<span>状态：</span>
						<select id="searchState"></select>
						<span>卡号：</span>
						<input type="text" id="searchCardNumber" />
					</P>
					<p>
						<span>姓名：</span>
						<input type="text" id="searchName" />
						<span>手机：</span>
						<input type="text" id="searchMp" />
						<span>级别：</span>
						<select id="searchLeave"></select>
					</p>
					<p>
						<input type="button" value="查询" class="btn" onclick="search()">
					</p>
				</div>
				<table width="100%" class="member_list" cellpadding="0"
				cellspacing="1" border="0">
					<caption>
						<strong>会员列表 <span id="sup">共0条</span></strong>
					</caption>
					<thead>
						<tr>
							<th>入会日期</th>
							<th>卡号</th>
							<th>姓名</th>
							<th>手机</th>
							<th>积分</th>
							<th>现金账户</th>
							<th>代金券</th>
							<th>优惠劵</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="memberList"></tbody>
				</table>
				<div id="pager" style="float: right;"></div>
			</div>
			<div class="fc"></div>
		</div>
		<!-- InstanceEndEditable -->
		<script type="text/javascript" src="../js/header.js"></script>
		<script type="text/javascript" src="../js/left.js"></script>
		<script type="text/javascript" src="../js/footer.js"></script>
		<script type="text/javascript">
			showTab(10, 3);
		</script>
	</body>
	<!-- InstanceEnd -->
</html>
